﻿using Minotaur.App.ViewModels;
using System;
using System.Windows;
using System.Windows.Input;

namespace Minotaur.App.Views
{
    /// <summary>
    /// LogIn.xaml 的交互逻辑
    /// </summary>
    public partial class LogIn : Window
    { 
        public LogIn()
        {
            InitializeComponent();
            this.KeyDown += OnKeyDown;
        }

        /// <summary>
        /// 登录时回车事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                var viewModel = this.DataContext as LogInViewModel;
                viewModel.LogInCommand.Execute(null);
            }
        }

        /// <summary>
        /// 窗体拖动事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        /// <summary>
        /// 页面元素初始化完成后再加载数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var viewModel = this.DataContext as LogInViewModel;
            viewModel.Dispatcher = this.Dispatcher;
            viewModel.CurrentWindow = this; 
        }
    }
}
